import 'package:flutter/material.dart';
import 'package:flutter_base/config/app_color.dart';
import 'package:flutter_base/pages/test_detail/widgets/test_card_base.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

/// 文本进度组件
class TextProgressBlock extends StatelessWidget {
  // final String title;
  // final String subtitle;
  // final List<TextProgressItem> items;
  final Map? data;

  const TextProgressBlock({
    super.key,
    // required this.title,
    // required this.subtitle,
    this.data,
  });

  @override
  Widget build(BuildContext context) {
    List paragraphs = [];
    if (data == null || data?.keys.contains('paragraphs') == false) {
      paragraphs = [
        {
          "content":
              "Everyone is unique, and your combination of personality traits makes you who you are today.",
          "highlight": false
        },
        {
          "content":
              "Understanding your strengths and room for growth is an important starting point for personal development.",
          "highlight": false
        },
        {
          "content":
              "Remember, personality traits are neither good nor bad, the key is how to play to your strengths.",
          "highlight": false
        },
        {
          "content":
              "Continuous self-reflection and learning will help you go further on the road of life.",
          "highlight": false
        },
        {
          "content":
              "Believe in yourself, embrace change, your potential is far greater than you think",
          "highlight": false
        },
      ];
    } else {
      paragraphs = data?['paragraphs'] ?? [];
    }

    return TestCardBase(
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          // 标题
          Text(
            'Summary of psychological analysis',
            style: TextStyle(
              fontFamily: 'Outfit',
              fontWeight: FontWeight.w600,
              fontSize: 14.sp,
              color: const Color(0xFF0C0A09),
              letterSpacing: 0.14,
              height: 1.26, // 17.64/14
            ),
          ),
          SizedBox(height: 4.w),
          // 副标题
          Text(
            'Analysis and guidance from professional psychologists',
            style: TextStyle(
              fontFamily: 'Outfit',
              fontWeight: FontWeight.w400,
              fontSize: 12.sp,
              color: const Color(0xFF7F909F),
              height: 1.26, // 15.12/12
            ),
          ),
          SizedBox(height: 30.w),
          // 进度项列表
          ...paragraphs.map((item) {
            // 如果不是最后一项，添加底部间距
            bool isLastItem = paragraphs.indexOf(item) == paragraphs.length - 1;
            return Padding(
              padding: EdgeInsets.only(bottom: isLastItem ? 0 : 30.w),
              child: TextProgressItem(
                text: item['content'],

                lineColor: TextProgressColors.getColorByIndex(paragraphs.indexOf(item)),
              ),
            );
          }),
        ],
      ),
    );
  }
}

/// 文本进度项
class TextProgressItem extends StatelessWidget {
  final String text;
  final Color lineColor;

  const TextProgressItem({
    super.key,
    required this.text,
    required this.lineColor,
  });

  @override
  Widget build(BuildContext context) {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        // 彩色竖线
        Container(
          width: 2.w,
          height: 32.w,
          color: lineColor,
        ),
        SizedBox(width: 12.w),
        // 文本内容
        Expanded(
          child: Text(
            text,
            style: TextStyle(
              fontFamily: 'Inter',
              fontWeight: FontWeight.w400,
              fontSize: 14.sp,
              color: const Color(0xFF8C9296),
              height: 1.21, // 16.94/14
            ),
          ),
        ),
      ],
    );
  }
}

/// 预设文本进度项颜色
class TextProgressColors {
  static const Color blue = Color(0xFF00A1FF);
  static const Color teal = Color(0xFF00CEB6);
  static const Color orange = Color(0xFFFFB900);
  static const Color pink = Color(0xFFFF6692);
  static const Color purple = Color(0xFF8965E5);
  
  /// 获取所有颜色列表
  static List<Color> get values => [blue, teal, orange, pink, purple];
  
  /// 根据索引循环获取颜色
  static Color getColorByIndex(int index) {
    return values[index % values.length];
  }
}
